﻿#If NETFX_CORE Then
Imports Windows.Storage.Streams

Namespace Global.Windows.UI.Xaml.Media.Imaging

    Public Module Extension

        <Extension()> _
        Public Sub FromBytes(ByRef [Me] As BitmapImage, ByVal data() As Byte)
            Dim bmp As New BitmapImage()
            Dim ims As New InMemoryRandomAccessStream()
            Dim writer As New DataWriter(ims.GetOutputStreamAt(0))
            writer.WriteBytes(data)
            writer.StoreAsync().GetResults()
            writer.FlushAsync().GetResults()
            bmp.SetSource(ims)
            [Me] = bmp
        End Sub

        <Extension()> _
        Public Async Sub FromBytesAsync(ByVal bmp As BitmapImage, ByVal data() As Byte)
            Dim ims As New InMemoryRandomAccessStream()
            Dim writer As New DataWriter(ims.GetOutputStreamAt(0))
            writer.WriteBytes(data)
            Await writer.StoreAsync()
            Await writer.FlushAsync()
            bmp.SetSource(ims)
        End Sub

    End Module

End Namespace

#End If